package com.ruoyi.web.controller.resturant;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.resturant.domain.ResBanner;
import com.ruoyi.resturant.service.IResBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图Controller
 *
 * @author Daniel
 * @date 2023-09-27
 */

@Anonymous
@RestController
@RequestMapping("/api/resturant/banner")
@Api(tags="轮播图管理")
public class ResBannerController extends BaseController {
    @Autowired
    private IResBannerService resBannerService;

    @ApiOperation("查询全部轮播图列表")        // 23201013517-李晓雪
    @GetMapping("/list0")
    public AjaxResult list0() {
        List<ResBanner> list = resBannerService.getAllResBanners();
        return AjaxResult.success(list);
    }

    /**
     * 获取轮播图详细信息
     */
    @ApiOperation(value = "根据id查询轮播图", notes = "TODO：取得某个轮播图的详细信息")    // 23201013517-李晓雪
    @ApiImplicitParam(name = "id", value = "轮播图ID",
            required = true, dataType = "long", paramType = "path",
            dataTypeClass = Long.class)
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(resBannerService.selectResBannerById(id));
    }

    /**
     * 查询轮播图列表
     **/
    @ApiOperation("按照名称查询轮播图")     // 23201013517-李晓雪
    @ApiImplicitParam(name = "name", value = "轮播图名称",
            dataType = "string", dataTypeClass = String.class)
    @GetMapping("/list")
    public AjaxResult list(@RequestParam(value = "name", required = false) String bannerName) {
        List<ResBanner> list = resBannerService.selectBannerByParam(bannerName);
        return AjaxResult.success(list);
    }

    /**
     * 新增轮播图
     */
    @ApiOperation("新增轮播图")           // 23201013517-李晓雪
    @PostMapping
    public AjaxResult add(@RequestBody ResBanner resBanner) {
        return AjaxResult.success(resBannerService.insertResBanner(resBanner));
    }

    /**
     * 修改轮播图
     */
    @ApiOperation("修改轮播图")           // 23201013517-李晓雪
    @PutMapping
    public AjaxResult edit(@RequestBody ResBanner resBanner) {
        return AjaxResult.success(resBannerService.updateResBanner(resBanner));
    }

    /**
     * 删除轮播图
     */
    @ApiOperation("删除轮播图")           // 23201013517-李晓雪
    @ApiImplicitParam(name = "id", value = "轮播图ID", required = true, dataType = "long", paramType = "path", dataTypeClass = Long.class)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return AjaxResult.success(resBannerService.deleteResBannerById(id));
    }
}